﻿using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CodeTool
{
    /// <summary>
    /// HtmlOperate.xaml 的交互逻辑
    /// </summary>
    public partial class HtmlOperate : Window
    {
        public HtmlOperate()
        {
            InitializeComponent();
        }

        //加密
        private void button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string source = txtSource.Text;
                if (string.IsNullOrEmpty(source))
                {
                    txtSource.Focus();
                    return;
                }
                string target = SecurityHelper.HtmlEncode(source);
                txtTarget.Text = target;
            }
            catch (Exception ex)
            {
                txtTarget.Text = "加密出错：" + ex.Message;
            }
        }
        //解密
        private void button_Copy_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string source = txtSource.Text;
                if (string.IsNullOrEmpty(source))
                {
                    txtSource.Focus();
                    return;
                }
                string target = SecurityHelper.HtmlDecode(source);
                txtTarget.Text = target;
            }
            catch (Exception ex)
            {
                txtTarget.Text = "解密出错：" + ex.Message;
            }
        }
    }
}
